Skip to content

fix: resolve a dep write's block through the symbol table - #958

Merged
NQPhuc merged 5 commits into
masterfrom
fix/dep-write-block-identity
Aug 14, 2026
Merged

fix: resolve a dep write's block through the symbol table#958
NQPhuc merged 5 commits into
masterfrom
fix/dep-write-block-identity

Conversation

@NQPhuc

@NQPhuc NQPhuc commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

syncDep aimed its edits at the wrong Dep block, or produced none.

  1. It located the block by comparing the endpoints as text.
  2. It read the last part as a column only when both sides had a dot.
  3. So in Dep { raw_events.payload -> stg_events } the left endpoint became schema raw_events, table payload, which matches nothing in the file.
  4. Separately, a target naming no columns matched any edge between the same two tables.

Effect: [color] and [note] writes on a mixed-level edge produced no edits at all, and create appended a duplicate block each time. A table-level write landed on the pair's first column-level block instead of a direct one.

findDepDefinition now locates the block by resolving both endpoints to table and column symbols, the way findRefDefinition does for a ref. A table-level target matches only an edge with no columns on either side. When none matches, create writes a new block.

Lasting Changes (Technical)

  • Added findDepDefinition in transform/utils/dep.ts, package-private like findRefDefinition beside it.
  • Deleted the functions that compared endpoints as text: findDepBlocks, findInlineDeps, depBlocksFromProgram, inlineDepsFromProgram, edgeFromInfix, fragmentsToEndpoint, extractInlineDepEdges, endpointMatches, endpointsEqual, plus the DepBlock and InlineDep types.
  • syncDep loses its third blocks? parameter. types/transform/index.d.ts is hand-written and still declared it, so the published types now match the code.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Documentation (if necessary)
  • Updated dbml-homepage/static/llms.txt (if docs/features changed)
  • Lint Checks Passed
  • Unit Tests Passed (2013 in dbml-parse)
  • Coverage Tests Passed
  • Integration Tests Passed
  • Code Review

🤖 Generated with Claude Code

Every write to a Dep block found its block by re-reading the block's own
source text and comparing endpoint names, and that re-reading resolves
`a.b` by counting fragments on both sides at once. A mixed-level edge such
as `a.x -> b` was therefore recorded as schema `a`, table `x`, which
nothing matches: colour and note writes returned no edits at all, and
every colour pick appended another block. A table-level target, whose
field list is empty, matched any edge on the pair, so a colour picked on
an aggregated line landed on the pair's first column-level block, where
the fieldless-only read never looks.

findDepDefinition walks DepMetadata, whose endpoints are already resolved
to table and column symbols in both the block and the inline form, and
compares the declarations they name, the way findRefDefinition does for a
ref. A table-level target matches only an edge with no columns on either
side. syncDep and updateElementSetting's dep path both go through it; the
folder-private endpoint comparers are deleted with their last callers, and
syncDep drops its unused pre-parsed-blocks parameter.

Found while retiring the old matching: a column's inline `[dep: -> b]`
naming a table does not compile, so two fixtures written that way were
invalid DBML that the text comparison edited regardless. Both are now
column-to-column.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

Benchmark Result

dbml-parse

suite 🏠 master 🔀 this branch change
18k 1217.971ms ±3.93% 1337.41ms ±5.04% 🔴 +9.8%
25k 2030.502ms ±6.2% 1861.153ms ±2.76% 🟢 -8.3%

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

Coverage Report

Commit: b7c449e

Overall Coverage

Metric Coverage
Lines ✅ 85.36% (9869/11561)
Statements ✅ 82.35% (10740/13042)
Functions ✅ 87.92% (2053/2335)
Branches ⚠️ 73.24% (6452/8809)

Package Coverage

Package Lines Statements Functions Branches
dbml-cli ✅ 100.00% ✅ 100.00% ✅ 100.00% ✅ 100.00%
dbml-connector ⚠️ 64.62% ⚠️ 64.36% ⚠️ 59.53% ⚠️ 59.09%
dbml-core N/A N/A N/A N/A
dbml-parse ✅ 87.21% ✅ 83.85% ✅ 90.18% ⚠️ 74.15%

⚠️ Coverage Warnings

The following packages have coverage below 80%:

  • dbml-connector: 64.62% line coverage

Files with Coverage Below 80%

dbml-connector

9 file(s) below 80% coverage
File Lines Statements Functions Branches
src/connectors/bigquery/index.ts 0.00% 0.00% 0.00% 0.00%
src/utils/credential-loader.ts 0.00% 0.00% 0.00% 0.00%
src/utils/helpers.ts 0.00% 0.00% 0.00% 0.00%
src/connectors/snowflake/index.ts 10.56% 10.31% 0.00% 0.00%
src/utils/parseSchema.ts 46.15% 42.85% 28.57% 27.27%
src/connectors/connector.ts 66.66% 66.66% 100.00% 57.14%
src/connectors/oracle/tables.ts 71.25% 67.39% 100.00% 56.96%
src/connectors/oracle/index.ts 80.00% 80.76% 100.00% 25.00%
src/connectors/oracle/utils.ts 85.71% 85.71% 100.00% 71.42%

dbml-parse

97 file(s) below 80% coverage
File Lines Statements Functions Branches
src/compiler/queries/container/scope.ts 0.00% 0.00% 0.00% 0.00%
src/core/global_modules/program/utils/records.ts 0.00% 0.00% 0.00% 0.00%
src/services/code_actions/provider.ts 0.00% 0.00% 0.00% 0.00%
src/services/diagnostics/provider.ts 0.00% 0.00% 0.00% 0.00%
src/compiler/queries/pipeline/interpret.ts 10.52% 12.19% 66.66% 41.66%
src/services/suggestions/crossFile.ts 19.35% 19.44% 33.33% 10.00%
src/core/local_modules/enum/index.ts 48.00% 46.29% 57.14% 52.63%
src/core/global_modules/project/interpret.ts 52.50% 46.66% 83.33% 23.07%
src/compiler/queries/legacy/parse.ts 53.84% 46.66% 50.00% 25.00%
src/compiler/projectLayout/layout.ts 54.16% 53.84% 75.00% 52.63%
src/core/local_modules/dep/index.ts 59.37% 58.82% 100.00% 53.57%
src/core/global_modules/enum/bind.ts 60.00% 62.50% 83.33% 37.50%
src/core/local_modules/ref/index.ts 62.50% 61.76% 100.00% 57.14%
src/core/types/report.ts 62.96% 56.66% 76.92% 57.14%
src/core/global_modules/records/utils/data/values.ts 63.30% 55.71% 72.72% 49.28%
src/compiler/queries/legacy/token.ts 66.66% 66.66% 66.66% 100.00%
src/core/local_modules/program/index.ts 66.66% 69.23% 75.00% 62.50%
src/core/types/symbol/symbols.ts 67.36% 59.51% 61.71% 52.43%
src/core/global_modules/note/bind.ts 69.23% 71.42% 83.33% 50.00%
src/core/local_modules/checks/index.ts 69.23% 75.00% 100.00% 64.28%
src/core/local_modules/project/index.ts 73.07% 73.07% 100.00% 68.18%
src/compiler/queries/utils.ts 73.17% 73.43% 84.61% 52.17%
src/core/global_modules/project/bind.ts 73.33% 75.00% 100.00% 50.00%
src/core/local_modules/indexes/index.ts 73.68% 69.35% 63.63% 64.28%
src/core/local_modules/tablePartial/validate.ts 73.91% 73.04% 81.33% 58.42%
src/core/local_modules/use/index.ts 73.91% 75.00% 75.00% 78.12%
src/core/local_modules/indexes/validate.ts 74.28% 74.66% 90.90% 56.00%
src/core/local_modules/note/index.ts 75.00% 75.86% 75.00% 72.72%
src/core/local_modules/records/index.ts 75.60% 76.19% 100.00% 68.08%
src/core/local_modules/project/validate.ts 75.86% 75.86% 100.00% 56.25%
src/core/global_modules/indexes/bind.ts 76.31% 74.35% 90.90% 68.96%
src/core/local_modules/custom/index.ts 76.47% 76.19% 80.00% 75.00%
src/core/global_modules/records/utils/data/sqlTypes.ts 76.59% 80.64% 82.35% 72.22%
src/core/local_modules/metadata/index.ts 77.77% 76.92% 75.00% 75.00%
src/core/local_modules/note/validate.ts 78.00% 75.92% 82.35% 67.64%
src/core/global_modules/tablePartial/interpret.ts 78.12% 70.90% 78.94% 53.84%
src/core/types/relation.ts 79.31% 73.52% 58.33% 80.00%
src/core/types/filepath.ts 79.48% 78.57% 77.77% 70.37%
src/core/global_modules/program/utils/external.ts 80.00% 80.00% 100.00% 70.00%
src/core/global_modules/tableGroup/bind.ts 80.00% 80.00% 100.00% 57.14%
src/core/global_modules/utils.ts 80.24% 77.27% 72.72% 65.51%
src/core/local_modules/records/validate.ts 80.28% 80.55% 93.75% 72.30%
src/core/global_modules/ref/bind.ts 80.64% 80.64% 90.00% 70.00%
src/core/global_modules/records/utils/constraints/helper.ts 81.08% 80.48% 82.35% 76.47%
src/core/global_modules/indexes/interpret.ts 81.39% 72.00% 100.00% 56.66%
src/core/local_modules/tablePartial/index.ts 81.48% 81.48% 100.00% 77.27%
src/core/local_modules/diagramView/validate.ts 81.57% 78.04% 84.21% 72.72%
src/core/local_modules/checks/validate.ts 81.63% 82.69% 93.75% 70.00%
src/core/local_modules/enum/validate.ts 82.25% 78.78% 81.25% 71.05%
src/core/global_modules/records/bind.ts 82.92% 83.72% 93.75% 67.30%
src/compiler/queries/container/token.ts 83.33% 85.71% 100.00% 75.00%
src/core/parser/parser.ts 84.29% 84.59% 100.00% 75.79%
__tests__/utils/compiler.ts 84.39% 81.91% 100.00% 59.66%
src/services/suggestions/provider.ts 84.40% 81.01% 91.17% 72.72%
src/compiler/queries/transform/syncDep.ts 84.84% 84.21% 100.00% 63.33%
__tests__/utils/mocks.ts 85.71% 86.20% 75.00% 100.00%
src/core/local_modules/dep/validate.ts 85.71% 82.60% 93.33% 75.00%
src/services/suggestions/utils/index.ts 85.71% 85.71% 100.00% 75.86%
src/compiler/queries/transform/updateElementSetting.ts 86.79% 86.88% 100.00% 71.92%
src/services/suggestions/utils/useMerger.ts 86.95% 81.13% 100.00% 46.34%
src/core/global_modules/tablePartial/bind.ts 87.03% 87.27% 100.00% 71.42%
src/core/local_modules/metadata/validate.ts 87.50% 85.41% 100.00% 71.87%
src/services/suggestions/recordRowSnippet.ts 88.46% 87.09% 100.00% 73.80%
src/compiler/queries/nodeAtPosition.ts 88.88% 90.00% 100.00% 75.00%
src/core/global_modules/diagramView/index.ts 89.16% 86.23% 83.33% 78.18%
src/core/global_modules/tableGroup/interpret.ts 89.58% 89.58% 100.00% 77.27%
src/core/utils/note.ts 89.65% 87.14% 100.00% 78.33%
src/compiler/index.ts 90.90% 90.97% 73.68% 80.00%
src/core/global_modules/records/index.ts 90.90% 87.15% 100.00% 79.16%
src/core/types/symbol/metadata.ts 91.00% 79.34% 95.83% 63.74%
src/core/global_modules/table/index.ts 91.75% 89.86% 100.00% 77.29%
src/core/local_modules/table/validate.ts 92.22% 92.82% 98.03% 79.06%
src/core/global_modules/schema/index.ts 92.26% 82.46% 91.66% 70.07%
src/core/global_modules/table/interpret.ts 92.68% 84.73% 96.55% 66.66%
src/core/global_modules/diagramView/interpret.ts 94.59% 90.40% 92.85% 75.75%
src/services/suggestions/use.ts 94.68% 87.61% 100.00% 77.45%
src/core/global_modules/ref/interpret.ts 95.83% 94.11% 100.00% 78.84%
src/core/utils/interpret.ts 95.89% 92.00% 100.00% 75.64%
src/core/global_modules/records/interpret.ts 95.97% 92.59% 100.00% 79.54%
__tests__/examples/interpreter/multifile/utils.ts 96.00% 89.65% 100.00% 62.50%
src/core/global_modules/note/interpret.ts 96.29% 96.29% 100.00% 75.00%
src/core/global_modules/dep/interpret.ts 96.93% 92.72% 100.00% 76.19%
src/compiler/queries/canonicalName.ts 96.96% 92.10% 100.00% 76.66%
src/core/global_modules/metadata/utils.ts 97.01% 90.58% 100.00% 75.55%
src/core/global_modules/program/interpret.ts 97.52% 92.60% 100.00% 70.42%
src/core/global_modules/records/utils/constraints/pk.ts 97.61% 92.18% 96.66% 67.85%
src/core/global_modules/dep/bind.ts 97.82% 80.32% 100.00% 68.29%
src/compiler/queries/transform/renameTable.ts 99.05% 90.47% 100.00% 78.82%
src/compiler/queries/transform/utils/dep.ts 100.00% 87.50% 100.00% 73.68%
src/compiler/queries/transform/utils/ref.ts 100.00% 82.92% 100.00% 64.70%
src/core/global_modules/checks/interpret.ts 100.00% 88.88% 100.00% 60.00%
src/core/global_modules/metadata/bind.ts 100.00% 89.47% 100.00% 75.00%
src/core/global_modules/metadata/interpret.ts 100.00% 80.00% 100.00% 58.33%
src/core/global_modules/program/index.ts 100.00% 85.71% 100.00% 75.00%
src/core/global_modules/records/utils/constraints/unique.ts 100.00% 93.75% 100.00% 50.00%
src/core/utils/diagnostics_reporter/ref.ts 100.00% 100.00% 100.00% 70.83%
src/services/definition/provider.ts 100.00% 95.23% 100.00% 71.42%

@NQPhuc
NQPhuc requested a review from huydo862003 August 13, 2026 07:46

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some functions that don't seem to be used anywhere:

  • findInlineDeps: unused + unexported from dbml/parse -> Can we delete this 🤔
  • findDepBlocks: unused but exported from dbml/parse -> If not used anywhere else, we can also delete this.
  • depBlocksFromProgram
  • inlineDepsFromProgram
  • DepBlock and InlineDep type

:v I dont have much context. But if we're not intending to use these anywhere, we can delete these 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed un-unused (and incorrect) code in f02ceb2

@NQPhuc
NQPhuc merged commit 9ed1379 into master Aug 14, 2026
7 of 8 checks passed
@huydo862003 huydo862003 added the PR: Bug Fix 🐛 A type of pull request used for changelog categories label Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Bug Fix 🐛 A type of pull request used for changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants